package com.bf.electroplating.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bf.electroplating.pojo.dto.IdDTO;
import com.bf.electroplating.pojo.dto.tank.ElectroplatingTankDTO;
import com.bf.electroplating.pojo.vo.ResultVO;
import com.bf.electroplating.pojo.vo.tank.ElectroplatingTankVO;
import com.bf.electroplating.pojo.vo.tank.WorkshopTankAreaSummaryVO;
import com.bf.electroplating.service.ElectroplatingTankService;
import com.bf.electroplating.util.idempotent.Idempotent;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/tank")
@Tag(name = "镀槽管理", description = "镀槽信息管理")
public class ElectroplatingTankController {

    @Resource
    private ElectroplatingTankService electroplatingTankService;

    @PostMapping("/list")
    @Operation(summary = "获取镀槽列表", description = "分页获取镀槽列表信息")
    public ResultVO<Page<ElectroplatingTankVO>> getTankList(@RequestBody ElectroplatingTankDTO dto) {
        return ResultVO.ok(electroplatingTankService.getTankList(dto));
    }

    @PostMapping("/getTankById")
    @Operation(summary = "获取镀槽详情", description = "根据ID获取镀槽详细信息")
    public ResultVO<ElectroplatingTankVO> getTankById(@RequestBody IdDTO id) {
        return ResultVO.ok(electroplatingTankService.getTankById(Long.valueOf(id.getId())));
    }

    @Idempotent
    @PostMapping("/saveTank")
    @Operation(summary = "新增镀槽", description = "新增镀槽信息")
    public ResultVO<Boolean> saveTank(@RequestBody ElectroplatingTankVO vo) {
        return ResultVO.ok(electroplatingTankService.saveTank(vo), "保存成功");
    }

    @Idempotent
    @PostMapping("/updateTank")
    @Operation(summary = "修改镀槽", description = "修改镀槽信息")
    public ResultVO<Boolean> updateTank(@RequestBody ElectroplatingTankVO vo) {
        return ResultVO.ok(electroplatingTankService.updateTank(vo), "保存成功");
    }

    @PostMapping("/deleteTank")
    @Operation(summary = "删除镀槽", description = "根据ID删除镀槽信息")
    public ResultVO<Boolean> deleteTank(@RequestBody IdDTO id) {
        return ResultVO.ok(electroplatingTankService.deleteTank(Long.valueOf(id.getId())), "删除成功");
    }

    @PostMapping("/batch")
    @Operation(summary = "批量删除镀槽", description = "批量删除镀槽信息")
    public ResultVO<Boolean> batchDeleteTank(@RequestBody List<String> ids) {
        return ResultVO.ok(electroplatingTankService.batchDeleteTank(ids), "删除成功");
    }

//    @PostMapping("/getTanksByWorkshopId")
//    @Operation(summary = "根据车间ID获取镀槽列表", description = "根据车间ID获取该车间下的所有镀槽")
//    public ResultVO<List<ElectroplatingTankVO>> getTanksByWorkshopId(@RequestBody IdDTO id) {
//        return ResultVO.ok(electroplatingTankService.getTanksByWorkshopId(Long.valueOf(id.getId())));
//    }

    @PostMapping("/getWorkshopTankAreaSummary")
    @Operation(summary = "获取车间镀槽面积汇总", description = "根据车间ID获取该车间下所有镀槽的上报总面积和实际测量总面积统计")
    public ResultVO<WorkshopTankAreaSummaryVO> getWorkshopTankAreaSummary(@RequestBody IdDTO id) {
        return ResultVO.ok(electroplatingTankService.getWorkshopTankAreaSummary(Long.valueOf(id.getId())));
    }
}
